﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;

namespace Projektet.Controller
{
    class UpgradeController
    {
        Model.Player _player;
        public float PikemanHealthCost { get{return 30;}}
        public float ArcherDamageCost { get { return 40; } }
        public float KnightAttackSpeedCost { get { return 30; } }
        //public

        public UpgradeController(Model.Player player) 
        {
            _player = player;
        }

        public void CheckForUpgradeInput(KeyboardState newState, KeyboardState oldState) 
        {
            if(newState.IsKeyUp(Keys.D1) && oldState.IsKeyDown(Keys.D1))
            {
                UpgradePikemanHealth();
            }
            else if(newState.IsKeyUp(Keys.D2) && oldState.IsKeyDown(Keys.D2))
            {
                UpgradeArcherDamage();
            }
            else if (newState.IsKeyUp(Keys.D3) && oldState.IsKeyDown(Keys.D3))
            {
                UpgradeKnightAttackSpeed();
            }
        }

        public void UpgradePikemanHealth() 
        {
            if (_player._gold > PikemanHealthCost)
            {
                _player._unitStats.PikemanHealth *= 1.05f;
                _player._gold -= PikemanHealthCost;
                Console.WriteLine("Pikeman health: " + _player._unitStats.PikemanHealth);
            }             
        }

        public void UpgradeArcherDamage() 
        {
            if (_player._gold > ArcherDamageCost) 
            {
                _player._unitStats.ArcherDamage *= 1.05f;
                _player._gold -= ArcherDamageCost;
                Console.WriteLine("Archer Damage: " + _player._unitStats.ArcherDamage);
            }            
        }

        public void UpgradeKnightAttackSpeed() 
        {
            if (_player._gold > KnightAttackSpeedCost) 
            {
                _player._unitStats.KnightAttackSpeed *= 0.95f;
                _player._gold -= KnightAttackSpeedCost;
                Console.WriteLine("Knight AttackSpeed: " + _player._unitStats.KnightAttackSpeed);
            }            
        }
    }
}
